<?php
/*
  $Id: shopping_cart.php,v 1.73 2003/06/09 23:03:56 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  require("includes/application_top.php");

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SHOPPING_CART);

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SHOPPING_CART));
  
  require(DIR_WS_INCLUDES . 'template_top.php');
?>
<!-- body //-->
<!-- body_eof //-->
<!--middle area start-->

<div class="middle-area">
  <div class="innermidbox fl">
    <div class="innermidbox-top"></div>
    <div class="innermidbox-mid">
      <div class="pdt5 pdl20 pdr20 pdb5 minheight527px">
        <div class="breadcrumbs"><a href="index.php">Home</a> > <span><?php echo HEADING_TITLE; ?></span></div>
        <div class="spacer10"></div>
        <div class="">
          <h1 class="pagetitle"><?php echo HEADING_TITLE; ?></h1>
          <div class="hline"></div>
          <div class="spacer3"></div>
          <!--left panel start-->
          <?php include('includes/template_left.php'); ?>
          <!--left panel end-->
          <!--right panel start-->
          <div class="rightpanel mgl15 fl">
            <!--listing start-->
            <div class="shoppingtable"> <?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_SHOPPING_CART, 'action=update_product')); ?>
              <!--<table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
                <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_cart.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
              </tr>
            </table>-->
              <?php
              	if ($cart->count_contents() > 0)
              	{
            ?>
              <tr>
                <td><?php
                $info_box_contents = array();
                $info_box_contents[0][] = array('align' => 'center',
                                                'params' => 'class="productListing-heading"',
                                                'text' => TABLE_HEADING_REMOVE);
            
                $info_box_contents[0][] = array('params' => 'class="productListing-heading"',
                                                'text' => TABLE_HEADING_PRODUCTS);
            
                $info_box_contents[0][] = array('align' => 'center',
                                                'params' => 'class="productListing-heading"',
                                                'text' => TABLE_HEADING_QUANTITY);
            
                $info_box_contents[0][] = array('align' => 'right',
                                                'params' => 'class="productListing-heading"',
                                                'text' => TABLE_HEADING_TOTAL);
            
                $any_out_of_stock = 0;
                $products = $cart->get_products();
                for ($i=0, $n=sizeof($products); $i<$n; $i++) {
            // Push all attributes information in an array
                  if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
                    while (list($option, $value) = each($products[$i]['attributes'])) {
                      echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
                      $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix
                                                  from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                                                  where pa.products_id = '" . $products[$i]['id'] . "'
                                                   and pa.options_id = '" . $option . "'
                                                   and pa.options_id = popt.products_options_id
                                                   and pa.options_values_id = '" . $value . "'
                                                   and pa.options_values_id = poval.products_options_values_id
                                                   and popt.language_id = '" . $languages_id . "'
                                                   and poval.language_id = '" . $languages_id . "'");
                      $attributes_values = tep_db_fetch_array($attributes);
            
                      $products[$i][$option]['products_options_name'] = $attributes_values['products_options_name'];
                      $products[$i][$option]['options_values_id'] = $value;
                      $products[$i][$option]['products_options_values_name'] = $attributes_values['products_options_values_name'];
                      $products[$i][$option]['options_values_price'] = $attributes_values['options_values_price'];
                      $products[$i][$option]['price_prefix'] = $attributes_values['price_prefix'];
                    }
                  }
                }
            
                for ($i=0, $n=sizeof($products); $i<$n; $i++) {
                  if (($i/2) == floor($i/2)) {
                    $info_box_contents[] = array('params' => 'class="productListing-even"');
                  } else {
                    $info_box_contents[] = array('params' => 'class="productListing-odd"');
                  }
            
                  $cur_row = sizeof($info_box_contents) - 1;
            
                  $info_box_contents[$cur_row][] = array('align' => 'center',
                                                         'params' => 'class="productListing-data" valign="top"',
                                                         'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']));
            
                  $products_name = '<table border="0" cellspacing="2" cellpadding="2">' .
                                   '  <tr>' .
                                   '    <td class="productListing-data" align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '">' . tep_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>' .
                                   '    <td class="productListing-data" valign="top"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '"><b>' . $products[$i]['name'] . '</b></a>';
            
                  if (STOCK_CHECK == 'true') {
                    $stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
                    if (tep_not_null($stock_check)) {
                      $any_out_of_stock = 1;
            
                      $products_name .= $stock_check;
                    }
                  }
            
                  if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
                    reset($products[$i]['attributes']);
                    while (list($option, $value) = each($products[$i]['attributes'])) {
                      $products_name .= '<br><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';
                    }
                  }
            
                  $products_name .= '    </td>' .
                                    '  </tr>' .
                                    '</table>';
            
                  $info_box_contents[$cur_row][] = array('params' => 'class="productListing-data"',
                                                         'text' => $products_name);
            
                  $info_box_contents[$cur_row][] = array('align' => 'center',
                                                         'params' => 'class="productListing-data" valign="top"',
                                                         'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']));
                  
                  //CGDiscountSpecials start
                  $info_box_contents[$cur_row][] = array('align' => 'right',
                                                         'params' => 'class="productListing-data" valign="top"',
                                                         'text' => '<b>' . $currencies->display_price_nodiscount($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . '</b>');
                  //CGDiscountSpecials end
            
                }
            
                new productListingBox($info_box_contents);
            ?></td>
              </tr>
              <tr>
                <td align="right" class="main"><strong><?php echo SUB_TITLE_SUB_TOTAL; ?></strong>
                  <div class="totle">
                    <?php 
                    
                      //CGDiscountSpecials start
                      	global $customer_id;
                      	$query_price_to_guest = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " WHERE configuration_key = 'ALLOW_GUEST_TO_SEE_PRICES'");
                      	$query_price_to_guest_result = tep_db_fetch_array($query_price_to_guest);
						
                      	if(($query_price_to_guest_result['configuration_value']=='true') && !(tep_session_is_registered('customer_id'))) 					{
                         	echo $currencies->format($cart->show_total()); 
						}
						elseif (tep_session_is_registered('customer_id')) 
						{
                        	echo $currencies->format($cart->show_total()); 
                      	}
						else
						{
                        	echo PRICES_LOGGED_IN_TEXT; 
                      	}
                      //CGDiscountSpecials end
            
                    ?>
                  </div></td>
              </tr>
              <?php
                if ($any_out_of_stock == 1) {
                  if (STOCK_ALLOW_CHECKOUT == 'true') {
            ?>
              <tr>
                <td class="stockWarning" align="center"><br>
                  <?php echo OUT_OF_STOCK_CAN_CHECKOUT; ?></td>
              </tr>
              <?php
                  } else {
            ?>
              <tr>
                <td class="stockWarning" align="center"><br>
                  <?php echo OUT_OF_STOCK_CANT_CHECKOUT; ?></td>
              </tr>
              <?php
                  }
                }
            ?>
              <tr>
                <td><div class="spacer20"></div>
                  <?php echo tep_submit('','class="update-btn fl"'); ?>
                  <?php
                        $back = sizeof($navigation->path)-2;
                        if (isset($navigation->path[$back])) 
                        {
                    ?>
                  <a href="<?=tep_href_link($navigation->path[$back]['page'], tep_array_to_string($navigation->path[$back]['get'], array('action')), $navigation->path[$back]['mode'])?>">
                  <div class="continue-btn fl mgl10"></div>
                  </a>
                  <?php
                        }
                    ?>
                  <a class="checkoutsmall-btn fl mgl10" href="<?=tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')?>" ></a></td>
              </tr>
              <?php
              } 
              	else 
              	{
            ?>
              <div style="width:100%">
                <?php new infoBox(array(array('text' => TEXT_CART_EMPTY))); ?>
                <div class="spacer10"></div>
                <a href="<?=tep_href_link(FILENAME_DEFAULT)?>" title="Continue Shopping with Swagon" >
                <div class="continue-btn" style="float:right;"></div>
                </a> </div>
              <?php
  				}
			?>
              </form>
            </div>
            <!--listing end-->
          </div>
          <!--right panel end-->
          <div class="spacer10"></div>
        </div>
      </div>
    </div>
    <div class="innermidbox-bottom"></div>
  </div>
</div>
<!--middle area end-->
<div class="spacer25"></div>
</div>
<?php
    require(DIR_WS_INCLUDES . 'template_bottom.php');
    require(DIR_WS_INCLUDES . 'application_bottom.php'); 
?>